import { registerMicroApps, start, addGlobalUncaughtErrorHandler } from 'qiankun'
import Vue from 'vue'

const microHandler = {
  beforeLoad: [
    (app) => { console.log('beforeLoad----------', app) }
  ], // 预加载
  beforeMount: [
    (app) => { console.log('beforeMount----------', app) }
  ], // 挂载前回调
  afterMount: [
    (app) => { console.log('afterMount----------', app) }
  ], // 挂载后回调
  beforeUnmount: [
    (app) => { console.log('beforeUnmount----------', app) }
  ], // 卸载前回调
  afterUnmount: [
    (app) => { console.log('afterUnmount----------', app) }
  ], // 卸载后回调
}

// 添加全局的未捕获异常处理器
// addGlobalUncaughtErrorHandler(errorHandler: (event:Event|string) => {
//   Vue.prototype.$loading(option: {}).close()
// })

export const registerApps = (app) => {
  // 注册微应用
  registerMicroApps(app, microHandler)
  // 启动微应用
  start()
  // start(opts: {
  //   prefetch: 'none'
  // })
}